package com.mercycrazy.springframework.aop.aspectj;

import com.mercycrazy.springframework.aop.Pointcut;
import com.mercycrazy.springframework.aop.PointcutAdvisor;
import org.aopalliance.aop.Advice;

/**
 * 表达式切面实现
 *
 * @author <a href="mailto:1443424326@qq.com">mercycrazy</a>
 * @since 2022-11-30
 */
public class AspectjExpressionPointcutAdvisor implements PointcutAdvisor {

    private AspectJExpressionPointcut pointcut;

    // 方法拦截器（适配器实现）
    private Advice advice;

    private String expression;

    public void setExpression(String expression) {
        this.expression = expression;
    }

    @Override
    public Advice getAdvice() {
        return advice;
    }

    public void setAdvice(Advice advice) {
        this.advice = advice;
    }

    @Override
    public Pointcut getPointcut() {
        if (null == pointcut) {
            pointcut = new AspectJExpressionPointcut(expression);
        }
        return pointcut;
    }
}
